#include <scene_graph_edit.h>
#include <QtWidgets/QApplication>
#include <UI/control.h>
#include <simulation.h>
#include <gl_window.h>

int main(int argc, char *argv[])
{

    const auto scene_graph = stvkBunny();
    std::cout << "construct scene graph successfully!" << std::endl;
    const auto driver = std::make_shared<Driver>();

    QApplication application(argc, argv);
    Simulation simulation(scene_graph, driver, 0.04f);
    Control control(driver);
    control.move(900, 0);
    GLwindow window(scene_graph);
    window.resize(800, 600);
    window.move(0, 0);

    QThread thread;
    simulation.moveToThread(&thread);

    QObject::connect(&thread, SIGNAL(started()), &simulation, SLOT(start()));
    QObject::connect(&simulation, SIGNAL(updateWindow()), &window, SLOT(updateWindow()));
    QObject::connect(&simulation, SIGNAL(finished()), &thread, SLOT(quit()));
    QObject::connect(&simulation, SIGNAL(finished()), &window, SLOT(close()));

    thread.start();

    window.show();
    control.show();

    //enter into qt event loop
    application.exec();

    return 0;
}
